<?php

declare(strict_types=1);

namespace App\Services;

use App\Entity\SmsEntity;
use App\Services\Sms\SmsService;

class SmsVerifyCodeService
{
    public static function generateStr($length = 6, $isNumeric = true): string
    {
        $str = '';
        if ($isNumeric) {
            $str = sprintf('%0' . $length . 'd', random_int(0, pow(10, $length) - 1));
        } else {
            $chars = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789abcdefghjkmnpqrstuvwxyz';
            $max   = strlen($chars) - 1;
            for ($i = 0; $i < $length; $i++) {
                $str .= $chars[random_int(0, $max)];
            }
        }

        return $str;
    }

    public static function sendSMS($phone, $verifyCode)
    {
        $smsEntity                = app(SmsEntity::class);
        $smsEntity->signName      = '环健';
        $smsEntity->phone         = $phone;
        $smsEntity->templateCode  = 'SMS_202375491';
        $smsEntity->templateParam = [
            'code' => $verifyCode,
        ];

        return SmsService::sendSms($smsEntity);
    }

    //保洁员添加手机验证短信
    public static function sendCleanerAddVerfiyPhoneSms($phone, $verifyCode)
    {
        $smsEntity                = app(SmsEntity::class);
        $smsEntity->signName      = '新业务中台';
        $smsEntity->phone         = $phone;
        $smsEntity->templateCode  = 'SMS_193517494';
        $smsEntity->templateParam = [
            'code' => $verifyCode,
        ];

        return SmsService::sendSms($smsEntity);
    }

    //保洁员修改手机验证短信
    public static function sendCleanerEditVerfiyPhoneSms($phone, $verifyCode)
    {
        $smsEntity                = app(SmsEntity::class);
        $smsEntity->signName      = '新业务中台';
        $smsEntity->phone         = $phone;
        $smsEntity->templateCode  = 'SMS_194025093';
        $smsEntity->templateParam = [
            'code' => $verifyCode,
        ];

        return SmsService::sendSms($smsEntity);
    }

    //创建完成通知短信
    public static function sendCleanerCreateSuccessSms($phone, $newPassword)
    {
        $smsEntity                = app(SmsEntity::class);
        $smsEntity->signName      = '环健';
        $smsEntity->phone         = $phone;
        $smsEntity->templateCode  = 'SMS_194025880';
        $smsEntity->templateParam = [
            'code' => $newPassword,
        ];

        return SmsService::sendSms($smsEntity);
    }
}
